package gbl;

import java.awt.event.ActionEvent;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JToolBar;

/**
 * This class holdes all the actions for the toolbar, and adding these to the toolbar
 * 
 * @since 1.0
 * @author Solveig 
 * @version 1.0 
 */
public class GblToolbarAbstracts {
	private GblModel gblm;
	private ResourceBundle messages;
	private Locale currentLocale;
	
	
	/**
	    * Constructor. Get gblm class from gbl.java.
	    * @author Solveig 
	    * @version 1.0 
	    * Last modified by Solveig, 28/09/11
	    */
	public GblToolbarAbstracts(GblModel getgblm){
		gblm = getgblm;
	}
	
	
   /**
    * Setting up abstract actions for menu and toolbar
    * @author Solveig
    * @version 1.0 
    * Last modified by Solveig, 28/09/11
    */
   void toolbarAbstract(JToolBar toolbar){ 
	   currentLocale = Locale.getDefault();
	   messages = ResourceBundle.getBundle ("I18N", currentLocale);
	  
       /*------------------ACTION: Add new Row ---------------------------*/
	   
       /**
        * Call to function for adding new row to the table
        * 
        * @since 1.0
        * @author Jo
        * @Version 1.0
        */
       AbstractAction newRow = new AbstractAction("New row", 
    		   new ImageIcon(getClass().getResource("images/NEWROW.GIF"))) {
           public void actionPerformed(ActionEvent ae) {
         	  gblm.tableAddrow();        	
           }
       };
    	// Put shortcut to "newRow":
       newRow.putValue(AbstractAction.MNEMONIC_KEY, (int) 'R');
       newRow.putValue(AbstractAction.	SHORT_DESCRIPTION, "Add new row");
       
       
       /*--------------------- ACTION: new FIle ------------------------*/	
       
       /**
        * Call to function for creating a new file
        * 
        * @since 1.0
        * @author solveig
        * @version 1.0
        */
       AbstractAction newFile = new AbstractAction("New",
               new ImageIcon(getClass().getResource("images/NEW.GIF"))) {
           public void actionPerformed(ActionEvent ae) {
         	  gblm.tableNewfile();
           }
       };
       // Put shortcut to "newFile":
       newFile.putValue(AbstractAction.MNEMONIC_KEY, (int) 'N');
       newFile.putValue(AbstractAction.	SHORT_DESCRIPTION, messages.getString("ttNew"));
       

       /*--------------------- Load File ------------------------*/
       
       /**
        * Call to function for loading an existing file
        * 
        * @since 1.0
        * @author Solveig
        * @version 1.0
        */
       AbstractAction load = new AbstractAction("Load doc",
               new ImageIcon(getClass().getResource("images/OPENDOC.GIF"))) {
           public void actionPerformed(ActionEvent ae) {
        	   gblm.tableLoadfile();
           }
       };
    	// Put shortcut to "load":
       load.putValue(AbstractAction.MNEMONIC_KEY, (int) 'L');
       load.putValue(AbstractAction.SHORT_DESCRIPTION, messages.getString("ttLoad"));
       
       
       /*--------------------- save file ------------------------*/
       
       /**
        * Call to function for saving to an existing file
        *         
        * @since 1.0
        * @author Solveig
        * @version 1.0
        */
       AbstractAction save = new AbstractAction("Save",
               new ImageIcon(getClass().getResource("images/SAVE.GIF"))) {
           public void actionPerformed(ActionEvent ae) {
        	   gblm.tableSavefile();
           }
       };
   	 // Put shortcut to "save":
       save.putValue(AbstractAction.MNEMONIC_KEY, (int) 'S');
       save.putValue(AbstractAction.SHORT_DESCRIPTION, messages.getString("ttSave"));
       
      
       /*--------------------- export code ------------------------*/
       
       /**
        * Call to function for exporting some code to a new file
        * 
        * @since 1.0
        * @author Solveig
        * @version 1.0
        */
       AbstractAction export = new AbstractAction("Export Java",
               new ImageIcon(getClass().getResource("images/SAVEJAVA.GIF"))) {
           public void actionPerformed(ActionEvent ae) {
        	   gblm.tableGeneratefile();	//TODO: make sure its generate and not preview.
           }
       };
       // Put shortcut to "export":
       export.putValue(AbstractAction.MNEMONIC_KEY, (int) 'E');
       export.putValue(AbstractAction.SHORT_DESCRIPTION, messages.getString("genJav"));
       
       
       /*------------------Move ROW up -----------------------*/
       /*Call to function for moving the user up a row*/
       /*AbstractAction upRow = new AbstractAction("Move row up",
               new ImageIcon(getClass().getResource("images/MoveRowUp.GIF"))) {
           public void actionPerformed(ActionEvent ae) {
           	//TODO: Call to function OR actions performed by "upRow".
           }
       };*/
       //TODO: Missing shortcut/mnemonic to upRow, gblToolbar.
       
       
       
       /*------------------Move ROW down ---------------------*/
       /*Call to function for moving the user down a row*/
      /* AbstractAction downRow = new AbstractAction("Move row down",
               new ImageIcon(getClass().getResource("images/MoveRowDown.GIF"))) {
           public void actionPerformed(ActionEvent ae) {
        	   //TODO: Call to function OR actions performed by "downRow".
           }
       };*/
       //TODO: Missing shortcut/mnemonic to downRow, gblToolbar.


       /*--------------------- ACTION: About ------------------------*/
       
       /**
        * Shows the About-dialog
        *          
        * @since 1.0
        * @author Solveig
        * @version 1.0
        */
       AbstractAction about = new AbstractAction("About", 
    		   new ImageIcon(getClass().getResource("images/HELP.GIF"))) {
           public void actionPerformed(ActionEvent ae) {
           		gblm.tableAboutgbl(); 
           }
       };
       // Put shortcut to "About":
       about.putValue(AbstractAction.MNEMONIC_KEY, (int) 'A');
       about.putValue(AbstractAction.SHORT_DESCRIPTION, messages.getString("ttAbout"));
       
       
       
       
       
       
     
       /*----------------------Layout------------------------*/
       
       /**
        * Adding alle the actions to the toolbar
        *         
        * @since 1.0
        * @author Solveig/jo
        * @version 1.0
        */
       toolbar.add(newFile);
       toolbar.add(load);
       toolbar.add(save);
       toolbar.add(export);
       toolbar.add(newRow);
       //toolbar.add(upRow);
       //toolbar.add(downRow);
       toolbar.add(about);
   }
         	   
}
